package Engine;

import Creature.Food;
import Item.Item;

import java.io.File;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.Scanner;

public class GameLoader {
    public static final String GAME_FILE = "res/stu.txt";
    System1 sys;
    GameLoader(System1 system1){
        sys=system1;
    }
    public boolean loadGame() {
        try {
            Scanner scanner = new Scanner(new File(GAME_FILE));
            sys.player.setMoney(scanner.nextInt());
            sys.player.setSan(scanner.nextInt());
            sys.player.setHungry(scanner.nextInt());
            sys.player.setHealth(scanner.nextInt());
            sys.player.setCharm(scanner.nextInt());
            sys.player.setPower(scanner.nextInt());
            sys.player.setFatigue(scanner.nextInt());
            sys.days= scanner.nextInt()-1;
            sys.eventLine.keyEventIndex= scanner.nextInt();
            int foodNum=scanner.nextInt();
            for (int i = 0; i < foodNum; i++) {
                sys.player.foods.add(new Food(scanner.next()));
            }
            int itemNum=scanner.nextInt();
            for (int i = 0; i < itemNum; i++) {
                sys.player.itemList.add(new Item(scanner.next()));
            }

        } catch (FileNotFoundException e) {
            System.out.println("游戏文件读取错误！");
            return false;
        }
        return true;
    }

    public boolean initGame() {
        try {
            Scanner scanner = new Scanner(new File("res/init.txt"));
            sys.player.setMoney(scanner.nextInt());
            sys.player.setSan(scanner.nextInt());
            sys.player.setHungry(scanner.nextInt());
            sys.player.setHealth(scanner.nextInt());
            sys.player.setCharm(scanner.nextInt());
            sys.player.setPower(scanner.nextInt());
            sys.player.setFatigue(scanner.nextInt());
            sys.days= scanner.nextInt()-1;
            sys.eventLine.keyEventIndex= scanner.nextInt();
            int foodNum=scanner.nextInt();
            for (int i = 0; i < foodNum; i++) {
                sys.player.foods.add(new Food(scanner.next()));
            }
            int itemNum=scanner.nextInt();
            for (int i = 0; i < itemNum; i++) {
                sys.player.itemList.add(new Item(scanner.next()));
            }

        } catch (FileNotFoundException e) {
            System.out.println("游戏文件读取错误！");
            return false;
        }
        return true;
    }

}
